package com.example.zlx.controller;

import com.example.zlx.entity.Economic;
import com.example.zlx.entity.User;
import com.example.zlx.service.EconomicService;
import com.example.zlx.util.Const;
import com.example.zlx.util.ResponseCodeEnum;
import com.example.zlx.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/manager/economic")
public class EconomicController {
    @Autowired
    private EconomicService economicService;
    //通过ID获取
    @GetMapping("/getEconomicById")
    public ServerResponse<Economic> getPlumberById(HttpSession session, @RequestParam(value = "id") Integer id){
        User adminstratorInfo= (User) session.getAttribute(Const.CURRENT_USER);
        if(adminstratorInfo==null){
            return ServerResponse.createByErrorCodeMessage(ResponseCodeEnum.NEED_LOGIN.getCode(),ResponseCodeEnum.NEED_LOGIN.getDesc());
        }
        System.out.println("11111111111111");
        return  economicService.getEconomicById(id);
    }

    @GetMapping("/listAll")
    public ServerResponse<String> list(HttpSession session) {
        User adminstratorInfo= (User) session.getAttribute(Const.CURRENT_USER);
        if (adminstratorInfo == null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCodeEnum.NEED_LOGIN.getCode(), ResponseCodeEnum.NEED_LOGIN.getDesc());
        }
        return economicService.listAll();
    }

}
